package com.gamatechno.solodestination;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.gamatechno.adapter.LazyAdapter;


import android.support.v4.app.Fragment;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.os.Build;

public class LihatDataActivity extends Activity {

	public static final String KEY_NAMA = "nama";
	ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
	ListView list;
	LazyAdapter adapter;
	//String id, name;
	//public List<data> dataList;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_lihat_data);
		String id, name;
		Intent main = getIntent();
		id = main.getExtras().getString("id");
		name = main.getExtras().getString("name");
		Log.i("id", id);
		Log.i("id", name);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.lihat_data, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	public class TampilTask extends AsyncTask<String, Void, Boolean> {

		ProgressDialog dialog = new ProgressDialog(LihatDataActivity.this);

		protected void onPreExecute() {
			dialog.setMessage(" Mengakses Data ");
			dialog.show();
		}

		protected void onPostExecute(Boolean result) {
			dialog.dismiss();
			setListviw();
		}

		@Override
		protected Boolean doInBackground(String... params) {
			// TODO Auto-generated method stub

			
			try {
			
				for (int i = 0; i < 8; i++) {
					// // creating new HashMap
					HashMap<String, String> map = new HashMap<String, String>();
					//
					// // adding each child node to HashMap key => value
					 //map.put(KEY_ID, );
					// map.put(KEY_NAMA, json.getString("nama"));
					// map.put(KEY_PANGKAT, json.getString("pangkat"));
					// map.put(KEY_NOAIC, json.getString("nomor_ak"));
					// map.put(KEY_NOSEN, json.getString("nomor_senjata"));
					// map.put(KEY_STATUS, json.getString("keterangan"));

					// // adding HashList to ArrayList
					songsList.add(map);
					//
				}

			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			return true;
		}

	}

	public void setListviw() {

		list = (ListView) findViewById(R.id.ListView01);

		// Getting adapter by passing xml data ArrayList
		adapter = new LazyAdapter(LihatDataActivity.this, songsList);
		list.setAdapter(adapter);

	}

}
